package com.borrowed.book.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    @Value("${book.image.fileOriPath}")
    private  String fileOriPath;//附件上传路径
    @Value("${book.image.fileOrmPath}")
    private String fileOrmPath;//文件获取映射路径

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //建立本地存储路径和虚拟路径映射关系
        registry.addResourceHandler(fileOrmPath+"/**").addResourceLocations("file:"+fileOriPath+"/");
        //因为自定义实现了WebMvcConfigurationSupport，springboot默认实现的静态资源文件映射关系需要加上去，不然静态资源文件访问不到
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/","classpath:/META-INF/resources/","classpath:/resources/","classpath:/public/");
        //classpath:/META-INF/resources/,classpath:/resources/, classpath:/static/, classpath:/public/,file:${web.upload-path}
        super.addResourceHandlers(registry);
    }
}
